var Utils = (function() {
  function setOpacity(el, opacity) {
    if (el.style.opacity != undefined) {
      el.style.opacity = opacity / 100;
    } else {
      el.style.filter = "alpha(opacity=" + opacity + ")";
    }
  }
  function addEvent(el, type, fn) {
    if(document.addEventListener) {
      el.addEventListener(type, fn, false);
      return () => {
        el.removeEventListener(type, fn, false);
      };
    } else if(document.attachEvent) {
      var bound = function() {
          return fn.apply(el, arguments)
      }
      el.attachEvent('on' + type, bound);
      return () => {
        el.detachEvent('on' + type, bound);
      }
    }
  }
  function getStyle(el, prop) {
    return el.currentStyle ? el.currentStyle[prop] : document.defaultView.getComputedStyle(el)[prop]
  }
  function includes(arr, item) {
    var result = false;
    for(var i = 0; i < arr.length; i++) {
      if(arr[i] == item) {
        result = true;
        break;
      }
    }
    return result;
  }
  function indexOf(arr, item) {
    var result = -1;
    for(var i = 0; i < arr.length; i++) {
      if(arr[i] == item) {
        result = i;
        break;
      }
    }
    return result;
  }
  function addClass(el, className) {
    var currClasses = el.className.split(/\s+/);
    if(!includes(currClasses, className)) {
      currClasses.push(className);
      el.className = currClasses.join(' ');
    }
  }
  function containClass(el, className) {
    var currClasses = el.className.split(/\s+/);
    return includes(currClasses, className);
  }
  function removeClass(el, className) {
    var currClasses = el.className.split(/\s+/);
    var index = indexOf(currClasses, className) >= 0;
    if(index >= 0) {
      currClasses.splice(index, 1);
      el.className = currClasses.join(' ');
    }
  }

  function extend(target) {
    for(var i = 1; i < arguments.length; i++) {
      for (var key in arguments[i]) {
        if (Object.hasOwnProperty.call(arguments[i], key)) {
          target[key] = arguments[i][key];
        }
      }
    }
    return target;
  }
  function getScrollOffsets() {
    
  }
  // 判断parentNode 是否含有childNode(包括他俩为同一元素)
  function contains(parentNode, childNode) {
    if(parentNode === childNode) {
      return true;
    }
    if(!childNode) {
      return false;
    }
    return contains(parentNode, childNode.parentNode);
  }
  return {
    setOpacity,
    addEvent,
    getStyle,
    indexOf,
    removeClass,
    addClass,
    containClass,
    includes,
    extend,
    contains
  }
})();